package com.kapcb.mvc.runner;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.time.LocalDateTime;

/**
 * <a>Title: BaseApplicationRunner </a>
 * <a>Author: Kapcb <a>
 * <a>Description: BaseApplicationRunner <a>
 *
 * @author Kapcb
 * @version 1.0
 * @date 2024/4/21 12:59
 * @since 1.0
 */
@Slf4j
public class BaseApplicationRunner implements ApplicationRunner {

    @Setter(onMethod_ = {@Autowired})
    public Environment environment;

    @Setter(onMethod_ = {@Autowired})
    public ConfigurableApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (applicationContext.isActive()) {
            String applicationName = environment.getProperty("spring.application.name");
            log.info("--------------------------------------------------------");
            log.info("server name : {}", applicationName);
            log.info("server start up time : {}", LocalDateTime.now());
            log.info("--------------------------------------------------------");
        }
    }
}
